package com.guage.producter.controller;

import javax.annotation.Resource;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/rocketmq")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class RocketMQController {
	@Resource(name="rocketMQTemplate")
	@Lazy
    private RocketMQTemplate rocketMqTemplate;
	@GetMapping("test")
    public String test() {
		rocketMqTemplate.asyncSend("aaa", "bbbb", new SendCallback() {
			
			@Override
			public void onSuccess(SendResult sendResult) {
				System.out.println(sendResult);
			}
			
			@Override
			public void onException(Throwable e) {				
			}
		});

        return "success";
    }
}
